// PALETTE DEMO jquery
// slide PALETTE box
$(function() {
		//Menus
				//$("#navi ul.sub-menu").css({display: "none"});
				/*
				var $menuli = $('#navi ul.menu>li');
				var $current = $(".current-menu-item,.current-menu-parent,.current-menu-ancestor ");
				var $menuunit = $("#navi ul.menu li");
				$menuli.children("a").each(function(){
					$(this).siblings("ul.sub-menu").parent().children("a").children("span.subtitle").before("<div class='nav_tri'></div>");
					//$(this).siblings("ul.sub-menu").parent(".current-menu-item,.current-menu-parent,.current-menu-ancestor").children(".nav_tri").css("background-image","url('/wp/webzine/wp-content/themes/webzine/img/demo/" + lcolor + ".png')");
				});
				$menuunit.prepend("<div class='navhover'></div>");
				$menuunit.hover(function(){
					$(this).not("ul ul li").children(".navhover").slideDown(100);
					$(this).not($current).children("a").children(".nav_tri").css("background","url('/wp/webzine/wp-content/themes/webzine/img/menustri_sienna.png')");
					//$(this).addClass("navhover");
					$(this).children("a").css("color","#c14b2b");	
					$("#navi li li").removeClass("navhover");
					$(this).find('ul:first').delay(150).slideDown(200);
				},function(){	
					$(this).children(".navhover").delay(100).slideUp(100);
					$(this).not($current).children("a").children(".nav_tri").css("background","url('/wp/webzine/wp-content/themes/webzine/img/menustri_grey.png')")
					//$(this).not($current).removeClass("navhover");
					$(this).not($current).children("a").css("color","#999");
					$(this).find('ul:first').slideUp(100);
				})
				//$current.children(".navhover").css("display","block")
				//$current.addClass("navhover");
				$current.children("a").css("color","#c14b2b");	
				$current.children("a").children(".nav_tri").css("background","url('/wp/webzine/wp-content/themes/webzine/img/menustri_sienna.png')");*/
	// Color box	   
	$('#openclose').click(function()
	{
		var target = jQuery(this).parent('#styleswitcher');
		var animator = {left: "-130"};
		var animator2 = {left: "0"};	
		if(target.is('.display_switch'))
		{
			target.animate(animator, function()
			{
				target.removeClass('display_switch').addClass('display_switch_false');
			});
		}
		else
		{		
			target.animate(animator2, function()
			{
				target.removeClass('display_switch_false').addClass('display_switch');
			});			
		}
	});
	//choose skin
	$("#skin li").click(function() {
		switchSkin($(this).attr("class"));
	});	
	function switchSkin(sk) {
		if(sk == ""){} else {
			$("head").append("<link rel=stylesheet href=styles/"+sk+".css>");
		}
	}
	//choose color link font
	$("#bgcolor").bind('change',function(){
		var mybgcolor = new jscolor.color(document.getElementById('bgcolor'), {})	
		$(" body ").css("background-color","#"+ mybgcolor);
	});	
	//choose bg-image
	$("#bg_img li").click(function() {
		switchBg($(this).attr("class"));
	});	
	function switchBg(bg) {
		if(bg == ""){} else {
			$("body").css("background-image","url('img/" + bg + ".png')");
			$("body").css("background-repeat","repeat");
				if((bg == "pattern_bg_a")||(bg == "pattern_bg_b")||(bg == "pattern_bg_c")) {
					$("body").css("background-image", "url(img/" + bg + ".jpg)");
					$("body").css("background-repeat","repeat-y");
					$("body").css("background-position","center top");
					}
		}
	}
	//font link color
	$("#linkcolor li").click(function() {
		switchl($(this).attr("class"));
	});	
	function switchl(lcolor) {
		if(lcolor == ""){} else {
			$(".entry a,.wp-pagenavi a,.wp-pagenavi span,.wp-pagenavi .current,.comment-meta span.reply a,.readmore").css("color","#"+ lcolor);
			$(".readmore").css("background-image","url('img/demo/" + lcolor + ".png')")
			//box background color
			$(".backbg").css("background-color","#"+ lcolor);
			//select text color
			$("head").append("<style>::selection{background:#"+lcolor+"}::-moz-selection{background:#"+lcolor+"}::-webkit-selection {background:#"+lcolor+"}</style>");
			$("head").append("<style>#filterable li.current a{color:#"+lcolor+"}</style>");
			//focus on header search
			$(".textboxsearch_header").focus(function(){
				$(this).parent().css("border-color","#"+ lcolor);
			}).focusout(function(){
				$(this).parent().css("border-color","#313131");
			});
			//focus on respond 
			$("#idi_name,#idi_mail,#idi_website,#idi_text").focus(function(){
				$(this).css("border-color","#"+ lcolor);
			}).focusout(function(){
				$(this).css("border-color","#303030");
			});
			$("#author,#email,#url,#comment").focus(function(){
				$(this).css("border-color","#"+ lcolor);
			}).focusout(function(){
				$(this).css("border-color","#ccc");
			});
			//hover on main list Title
			$("li.list_box h2 a,#comments_box .author a").hover(function(){
				$(this).css("color","#"+ lcolor);
			},function(){
				$(this).css("color","#333");
			});
			$(".comment-meta span.reply a").hover(function(){
				$(this).css("color","#"+ lcolor);
			},function(){
				$(this).css("color","#333");
			});
			//hover siderbar widget list 
			$(".widget_archive li a,.clum2_sidebar_unit li.menu-item a,.clum2_sidebar_unit li.cat-item a,li.widget_pages li a,li.widget_links li a,li.widget_meta li a,li.widget_rss li a").hover(function(){
				$(this).css("background-image","url('img/demo/" + lcolor + "_w.png')");																	
			},function(){
				$(this).css("background-image","url('img/widgetlist_grey.png')");
			});
			//hover readmore
			/*$(".readmore").css("background-image","url('/wordpress29/wp-content/themes/webzine/img/demo/" + lcolor + ".png')");*/
			$(".readmore").hover(function(){
				$(this).css("background-image","url('img/menustri_dark.png')");
				$(this).css("color","#333");
			},function(){
				$(this).css("background-image","url('img/demo/" + lcolor + ".png')");
				$(this).css("color","#"+ lcolor);
			});
			//hover general
			$(".clum2_sidebar_unit a,wp-pagenavi a,li.widget_homelist li a,.clum2_box_meta a,.clum2_unit .clum2_unit_meta a,.breadcrumbs a,.job_title").hover(function(){
				$(this).css("color","#"+ lcolor);															
			},function(){
				$(this).css("color","#666666");
			});
			//hover footer text
			$(".textinfo a").hover(function(){
				$(this).css("color","#"+ lcolor);															
			},function(){
				$(this).css("color","#454545");
			});
			//hover footer contact form button
			$("#footunderwrap .idi_send").hover(function(){
				$(this).css("background-color","#"+ lcolor);															
			},function(){
				$(this).css("background-color","#2c2c2c");
			});
			//hover on repond comment
			$("#respond .respondbtn").hover(function(){
				$(this).css("background-color","#"+ lcolor);															
			},function(){
				$(this).css("background-color","#717171");
			});
			$("#respond .send_btn").hover(function(){
				$(this).css("background-color","#"+ lcolor);															
			},function(){
				$(this).css("background-color","#717171");
			});
			//Menus active
			var $menuli = $('#navi ul.menu>li');
			var $current = $(".current-menu-item,.current-menu-parent,.current-menu-ancestor ");
				$menuli.children("a").each(function(){
					$(this).siblings("ul.sub-menu").parent(".current-menu-item,.current-menu-parent,.current-menu-ancestor").children(".nav_tri").css("background","url('img/demo/" + lcolor + ".png')");			
				});
			/**/$("#navi ul.menu li").hover(function(){
				$(this).children("a").css("color","#"+ lcolor);
				$(this).children("a").children(".nav_tri").css("background","url('img/demo/" + lcolor + ".png')");
			},function(){	
				$(this).not(".current-menu-item,.current-menu-parent,.current-menu-ancestor ").children("a").css("color","#999");
				$(this).not($current).children("a").children(".nav_tri").css("background","url('img/menustri_grey.png')");
			});
			$current.children("a").css("color","#"+ lcolor);
			$current.children("a").children(".nav_tri").css("background","url('img/demo/" + lcolor + ".png')");
		}
	}
	//font select
	 $("#fontselect").change(function () {
           var str = "";
          $("select#fontselect option:selected").each(function () {
                str += $(this).text() + " ";
				if(str == "abel"){
					$(".guidewrap,h1,h2,h3,h4,h5").css("font-family","abel")
				} else {
					$("head").append("<link href=http://fonts.googleapis.com/css?family="+str+" rel=stylesheet type=text/css>");
					$(".guidewrap,h1,h2,h3,h4,h5").css("font-family",str)
				}
              });
          
        })
        .trigger('change');
});